<?php
header("Content-Type: text/html; charset=utf-8");

//https://push2.eastmoney.com/api/qt/clist/get?cb=jQuery112302796115870333258_1705329014997&fid=f62&po=1&pz=50&pn=2&np=1&fltt=2&invt=2&ut=b2884a393a59ad64002292a3e90d46a5&fs=m%3A0%2Bt%3A6%2Bf%3A!2%2Cm%3A0%2Bt%3A13%2Bf%3A!2%2Cm%3A0%2Bt%3A80%2Bf%3A!2%2Cm%3A1%2Bt%3A2%2Bf%3A!2%2Cm%3A1%2Bt%3A23%2Bf%3A!2%2Cm%3A0%2Bt%3A7%2Bf%3A!2%2Cm%3A1%2Bt%3A3%2Bf%3A!2&fields=f12%2Cf14%2Cf2%2Cf3%2Cf62%2Cf184%2Cf66%2Cf69%2Cf72%2Cf75%2Cf78%2Cf81%2Cf84%2Cf87%2Cf204%2Cf205%2Cf124%2Cf1%2Cf13

# pz=50&pn=2
# pz 每页显示多少条
# pn 页数


//详情

//https://push2.eastmoney.com/api/qt/stock/get?fltt=2&invt=2&secid=1.600089&fields=f57,f58,f107,f43,f169,f170,f171,f47,f48,f60,f46,f44,f45,f168,f50,f162,f177&ut=b2884a393a59ad64002292a3e90d46a5&cb=jQuery112308641160215683172_1721316865649&_=1721316865650
$url = "https://push2.eastmoney.com/api/qt/stock/get?fltt=2&invt=2&secid=1.600089&fields=f57,f58,f107,f43,f169,f170,f171,f47,f48,f60,f46,f44,f45,f168,f50,f162,f177&ut=b2884a393a59ad64002292a3e90d46a5&cb=jQuery112308641160215683172_1721316865649&_=1721316865650";
#secid=0.300122
#secid=1.600023
#secid=1.688692

$res_text = sendGetRequest($url);
result_text_str_post($res_text);

die;



$arr = ["11.23","83.51","84.84","7.43","58.18","192.44","88.44","10.20","44.56","77.67","88.89"];

//定义类型
$type_dict = array(
    0 => "无",
    1 => "ABCC",
    2 => "AABB",
    3 => "ABAB",
    4 => "ABCB"
);


foreach ($arr as $key => $val){
    $is_abcc = exist_mod($val);
    $temp_arr = array();
    echo $key."==>".$val."==".($is_abcc>0?"是":"否")."==模式==".$type_dict[$is_abcc];
    echo "<br/>";

}

//处理数据
function result_text_str_post($res_text){
    //分割字符串 (
    $str1 = explode("(",$res_text);
    //继续分割字符串 );
    $str2 = explode(");",$str1[1]);
    $_gp_data = json_decode($str2[0],true);

    $gp_data = $_gp_data["data"];

    echo "<p>";
    echo "名称：".$gp_data["f58"]."</br>";
    echo "代码：".$gp_data["f57"]."</br>";
    echo "当前价格：".$gp_data["f43"]."</br>";
    echo "当天涨幅：".$gp_data["f170"]."</br>";
    echo "换手率：".$gp_data["f168"]."</br>";
    echo "当天最高价格：".$gp_data["f44"]."</br>";
    echo "当天最低价格：".$gp_data["f45"]."</br>";
    echo "当天开盘价格：".$gp_data["f46"]."</br>";
    echo "成交量：".$gp_data["f47"]."</br>";
    echo "成交额：".$gp_data["f48"]."</br>";
    echo "量比：".$gp_data["f50"]."</br>";
    echo "昨天收盘价格：".$gp_data["f60"]."</br>";
    echo "市盈(动)：".$gp_data["f162"]."</br>";
    echo "价格涨幅：".$gp_data["f169"]."</br>";
    echo "</p>";

    /*

array(7) {
  ["rc"]=>
  int(0)
  ["rt"]=>
  int(4)
  ["svr"]=>
  int(177617569)
  ["lt"]=>
  int(1)
  ["full"]=>
  int(1)
  ["dlmkts"]=>
  string(0) ""
  ["data"]=>
  array(17) {
    ["f43"]=>
    float(13.62)  //当前价格
    ["f44"]=>
    float(13.73) //当天-最高价
    ["f45"]=>
    float(13.49) //当天-最低价格
    ["f46"]=>
    float(13.51) //当天开盘价格
    ["f47"]=>
    int(288994) //成交量
    ["f48"]=>
    float(393386810)  //成交额
    ["f50"]=>
    float(0.89)  //量比
    ["f57"]=>
    string(6) "600089" //股票代码
    ["f58"]=>
    string(12) "特变电工" //股票名称
    ["f60"]=>
    float(13.56)  //昨天收盘价格
    ["f107"]=>
    int(1)
    ["f162"]=>
    float(8.63)  //市盈(动)
    ["f168"]=>
    float(0.57)  //换手率0.57%
    ["f169"]=>
    float(0.06)  //价格涨幅 6分钱
    ["f170"]=>
    float(0.44)   //当天涨幅0.44%
    ["f171"]=>
    float(1.77)
    ["f177"]=>
    int(577)
  }
}
     */

}


//get 数据
function sendGetRequest($url) {
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

    $response = curl_exec($ch);

    if(curl_errno($ch)) {
        echo 'Curl error: '. curl_error($ch);
    }

    curl_close($ch);

    return $response;
}






//判断数值是否是ABCC模式
function exist_mod($num){
    $temp_arr = explode(".",$num);
    if(count($temp_arr)==2){
        //取整数
        $integer = $temp_arr[0];
        //获取小数
        $decimal = $temp_arr[1];
        //判断是否是ABCC模式
        $temp_abcc = exist_ABCC($decimal);
        if($temp_abcc > 0){
            //进一步确认是否是AABB模式
            $temp_aabb = exist_AABB($integer);
            if($temp_aabb){
                return $temp_aabb;
            }else{
                return $temp_abcc;
            }
        }else{
            $temp_abab = exist_ABAB($integer,$decimal);
            if($temp_abab){
                return $temp_abab;
            }else{
                $temp_abcb = exsit_abcb($integer,$decimal);
                return $temp_abcb;
            }

        }
    }
    return 0;
}
//判断是否是ABCC模式
function exist_ABCC($decimal){
    //排除是尾数是00情况（如22.00）
    if($decimal=="00"){
        return 1;
    }else{
        $mod = floor($decimal / 10);//向下取整数
        $fmod = fmod($decimal,10);//取余值
        if($mod==$fmod){
            return 1;
        }
    }
    return 0;
}

//判断是否是ABAB模式
function exist_ABAB($integer,$decimal){
    //判断是否是ABAB模式
    if($integer == $decimal){
        return 3;
    }else{
        return 0;
    }
}

//判断是否是AABB模式
function exist_AABB($integer){
    $mod = floor($integer / 10);//向下取整数
    $fmod = fmod($integer,10);//取余值
    if($mod==$fmod){
        return 2;
    }else{
        return 0;
    }
}

//判断是否是ABCB模式
function exsit_abcb($integer,$decimal){
    $integer_fmod = fmod($integer,10);//整数取余值
    $decimal_fmod = fmod($decimal,10);//整数取余值
    if($integer_fmod == $decimal_fmod){
        return 4;
    }else{
        return 0;
    }
}


